/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.giftmemo.ui.utils;

import com.alee.laf.button.WebButton;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
 *
 * @author Egor
 */
public class ButtonsPanel extends JPanel {

    private WebButton okButton;
    private WebButton applyButton;
    private WebButton cancelButton;

    public ButtonsPanel(ButtonsPanelState... buttonsPanelState) {
        okButton = new WebButton();
        applyButton = new WebButton();
        cancelButton = new WebButton();

        init(buttonsPanelState);
    }

    private void init(ButtonsPanelState... buttonsPanelState) {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        add(Box.createHorizontalGlue());
        for (int i = 0; i < buttonsPanelState.length; i++) {
            switch (buttonsPanelState[i]) {
                case APPLY_BUTTON:
                    add(applyButton);
                    add(Box.createHorizontalStrut(5));
                    break;
                case CANCEL_BUTTON:
                    add(cancelButton);
                    add(Box.createHorizontalStrut(5));
                    break;
                case OK_BUTTON:
                    add(okButton);
                    add(Box.createHorizontalStrut(5));
                    break;
            }
        }

        add(Box.createHorizontalGlue());
    }

    public void setOkButtonAction(Action okAction) {
        okButton.setAction(okAction);
    }

    public void setApplyButtonAction(Action applyAction) {
        applyButton.setAction(applyAction);
    }

    public void setCancelButtonAction(Action cancelAction) {
        cancelButton.setAction(cancelAction);
    }

    public static enum ButtonsPanelState {

        OK_BUTTON, APPLY_BUTTON, CANCEL_BUTTON;
    }

}
